package com.user.controller;

import com.user.dao.order.*;
import com.user.service.OrderService;
import com.user.utils.R;
import com.user.utils.WebSocketServer;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author : Yu
 * @Date 2024/1/8 11:37
 */

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;
    @Resource
    WebSocketServer webSocketServer;

    @PostMapping("/test")
    public void test() {
        webSocketServer.sendOneMessage("admin", "支付成功");
    }

    @PostMapping("/saveOrder")
    public R saveOrder(@RequestBody OrderDao order) throws IOException {
        return orderService.saveOrder(order);
    }

    @PostMapping("/getUserOrder")
    public R getOrder(@RequestBody QueryPageOrder order) {
        return orderService.getUserOrder(order);
    }

    @GetMapping("/getRestaurantOrder")
    public R getRestaurantOrder(@RequestParam Integer UserId) {
        return orderService.getRestaurantOrder(UserId);
    }

    @PostMapping("/toPay")
    public R pay(@RequestBody OrderPay orderPay) {
        return orderService.toPay(orderPay);
    }

    @PostMapping("/notify")
    public R handleAlipayNotify(HttpServletRequest request) {
        return orderService.payNotify(request);
    }

    @GetMapping("/refund")
    public R refund(@RequestParam Integer orderId) {
        return orderService.refund(orderId);
    }

    @GetMapping("test1")
    public R test1(@RequestParam Integer orderId) {
        return orderService.test1(orderId);
    }

    @GetMapping("test2")
    public R test2(@RequestParam Integer orderId) {
        return orderService.test2(orderId);
    }

    @PostMapping("/getOrder")
    public R getOrder(@RequestBody QueryPageOrderMerchant orderMerchant) {
        return orderService.getOrderByRestaurantId(orderMerchant);
    }

    @DeleteMapping("/cancelOrder")
    public R cancelOrder(@RequestParam Integer orderId) throws IOException {
        return orderService.cancelOrder(orderId);
    }

    @PostMapping("/score")
    public R score(@RequestBody ScoreDao scoreDao) {
        return orderService.score(scoreDao);
    }

    @GetMapping("/getOrderById")
    public R getOrderById(@RequestParam Integer orderId) {
        return orderService.getOrderById(orderId);
    }

    //获取今天和明天的订单
    @GetMapping("/getTodayOrder")
    public R getTodayOrder(@RequestParam Integer restaurantId) {
        return orderService.getTodayOrder(restaurantId);
    }
}
